package com.overlord.im.server.message.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.overlord.im.server.message.entity.OfflineMessageEntity;
import com.overlord.im.server.message.mapper.OfflineMessageMapper;
import org.springframework.stereotype.Service;

/**
 * @ClassName OfflineMessageService
 * @Author wuwei
 * @Description NONE
 * @Date 2020/6/3 10:59
 **/
@Service
public class OfflineMessageService extends ServiceImpl<OfflineMessageMapper, OfflineMessageEntity> {

    public IPage<OfflineMessageEntity> page(Long clientId, IPage<OfflineMessageEntity> page) {
        return page(page, new LambdaQueryWrapper<OfflineMessageEntity>().eq(OfflineMessageEntity::getMsgTo, clientId));
    }

    public void deleteByMessageId(Long messageId, Long clientId) {
        getBaseMapper().delete(
                new LambdaQueryWrapper<OfflineMessageEntity>().eq(OfflineMessageEntity::getMessageId, messageId)
                        .eq(OfflineMessageEntity::getMsgTo, clientId));
    }
}
